package com.sgcc.sx.pmos.e_sx_mall.adapter;

import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.sx.pmos.common.bean.RatioCurveBean;
import com.sgcc.sx.pmos.common.view.LineChartView;
import com.sgcc.pmos.nativesdk.R;

public class SelectCurveAdapter extends BaseQuickAdapter<RatioCurveBean.Bean, BaseViewHolder> {

    public SelectCurveAdapter() {
        super(R.layout.item_select_curve);
    }

    public interface OnItemClickListener {
        //条目点击
        void itemClickListener(int position, RatioCurveBean.Bean s);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RatioCurveBean.Bean s) {
        LinearLayout linearLayout = baseViewHolder.getView(R.id.llLineLayout);
        LinearLayout llLayout = baseViewHolder.getView(R.id.llLayout);
        baseViewHolder.setText(R.id.tvTitle, s.getRatioName());
        llLayout.setSelected(s.isSelect());
        linearLayout.removeAllViews();
        linearLayout.addView(new LineChartView(getContext(), s.getYAxis()));

        llLayout.setOnClickListener(view -> {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.itemClickListener(getItemPosition(s), s);
            }
        });


    }
}
